import { Controller, Get, Post, Body, Patch, Param, Delete, Res, UseGuards } from '@nestjs/common';
import { UserService } from './user.service';
import { LoginUserDto } from './dto/login-user.dto';
import { RegisterUserDto } from './dto/register-user.dto';
import { Response } from 'express';
import { LoginGuard } from 'src/login.guard';
@Controller('ap/user/')
export class UserController {
  constructor(private readonly userService: UserService) {}

  @Post('register')
  async register(@Body() registerUserDto: RegisterUserDto) {
      return this.userService.register(registerUserDto);
  }


  @Post('login')
  async login(@Body() loginUserDto: LoginUserDto,@Res({passthrough: true}) res: Response) {
    return this.userService.login(loginUserDto,res);
  }

  @Post('info')
  @UseGuards(LoginGuard)
  async  getUserInfo() {
    return this.userService.getUserInfo();
  }

  @Post('loginOut')
  @UseGuards(LoginGuard)
  async logout(@Res({passthrough: true}) res: Response) {
    return this.userService.logout(res);
  }


  @Post('/list')
  @UseGuards(LoginGuard)
  async userList() {
    return this.userService.getUserList();
  }

  @Post('add')
  @UseGuards(LoginGuard)
  async addUser(@Body() data: any) {
    return this.userService.addUser(data);
  }

  @Post('delete')
  @UseGuards(LoginGuard)
  async deleteUser(@Body() data: any) {
    return this.userService.deleteUser(data);
  }

  @Post('edit')
  @UseGuards(LoginGuard)
  async editUser(@Body() data: any) {
    return this.userService.editUser(data);
  }

}
